package com.wsx.rpc.grpc.service;

import com.wsx.rpc.grpc.Cache;
import com.wsx.rpc.grpc.DataService;
import org.springframework.stereotype.Service;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @author wangshuaixin
 * @Title: com.wsx.rpc.grpc.service.DataServiceImpl
 * @Description: TODO
 * @date 2018/12/26
 */
@Service
public class DataServiceImpl implements DataService {

    private static Map<String, Cache> map = new ConcurrentHashMap<>(1000);

    @Override
    public boolean set(Cache cache) {
        Cache n = map.put(cache.getId(), cache);
        if (null == n) {
            return true;
        }
        return n.getId().equals(cache.getId());
    }

    @Override
    public Cache get(String id) {
        return map.get(id);
    }
}
